<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
FlyUI Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="flyted-service.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>FlyUI</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>flyted-service.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		This script defines utilities for interacting with data from www.fly-ted.org.
 <BR/><BR/><B>Version: </B>$Revision:538 $ on $Date: 2008-08-27 09:08:41 +0100 (Wed, 27 Aug 2008) $ by $Author: aliman $
 <BR/><BR/><B>Requires:</B><UL>- YAHOO.util.Connect<BR/>- flyui.flyted.GeneNameMappings
 TODO license terms</UL><B>Author:</B> <a href="http://purl.org/net/aliman">Alistair Miles</a>, Graham Klyne, Jun Zhao
 <BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/flyted/ImagePool.html">flyui.flyted.ImagePool</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/flyted/ProbePool.html">flyui.flyted.ProbePool</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="flyui/flyted/Service.html">flyui.flyted.Service</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/**
 * <span class="attrib">@fileoverview</span>
 * This script defines utilities for interacting with data from www.fly-ted.org.
 * <span class="attrib">@author</span> &lt;a href="http://purl.org/net/aliman"&gt;Alistair Miles&lt;/a&gt;, Graham Klyne, Jun Zhao
 * <span class="attrib">@version</span> $Revision:538 $ on $Date: 2008-08-27 09:08:41 +0100 (Wed, 27 Aug 2008) $ by $Author: aliman $
 * <span class="attrib">@requires</span> YAHOO.util.Connect
 * <span class="attrib">@requires</span> flyui.flyted.GeneNameMappings
 * TODO license terms
 */</span>

<span class="comment">// create a namespace if not already defined</span>
flyui.namespace(<span class="literal">"flyui.flyted"</span>);


<span class="comment">/**
 * TODO doc me
 */</span>
flyui.flyted.Service = <span class="reserved">function</span> (endpointURL) {
	<span class="comment">/**
	 * <span class="attrib">@private</span>
	 */</span>
	<span class="reserved">this</span>._endpoint = endpointURL;
};


<span class="comment">// extend</span>
flyui.flyted.Service.<span class="reserved">prototype</span> = new flyui.sparql.Service();


<span class="comment">/**
 * TODO doc me
 */</span>
flyui.flyted.Service.<span class="reserved">prototype</span>.findImagesByFlytedProbeName = <span class="reserved">function</span>( probeName, success, failure ) {
    var _context = <span class="literal">"flyui.flyted.Service.prototype.findImagesByFlytedProbeName"</span>;
	try {
		flyui.info(<span class="literal">"probeName: "</span>+probeName, _context);
<span class="comment">//		var successAdapter = flyui.flyted.Service._buildSuccessAdapterForFindImagesByFlytedProbeName(success);</span>
        var successChain = flyui.chain(flyui.flyted.Service.responseToImages, success);	
		var query = flyui.flyted.Service._buildQueryForFindImagesByFlytedProbeName(probeName);
		<span class="reserved">this</span>.query(query, successChain, failure);
	}catch (error) {
        throw new flyui.UnexpectedException(_context, error);
    }
};


<span class="comment">/**
 * Find images in the FlyTED database for the given flybase gene ID.
 * <span class="attrib">@param</span> {String} flybaseGeneID the flybase gene ID e.g. FBgn012345
 * <span class="attrib">@param</span> {Function} success the success case callback function, which must accept an array of 
 * flyui.flyted.Image objects
 * <span class="attrib">@param</span> {Function} failure the failure case callback function, which must accept a YUI HTTP response object
 */</span>
flyui.flyted.Service.<span class="reserved">prototype</span>.findImagesByFlybaseGeneID = <span class="reserved">function</span>( flybaseGeneID, success, failure) {
    var _context = <span class="literal">"flyui.flyted.Service.prototype.findImagesByFlybaseGeneID"</span>;
	try {
		flyui.info(<span class="literal">"flybaseGeneID: "</span>+flybaseGeneID, _context);
<span class="comment">//		var successAdapter = flyui.flyted.Service._buildSuccessAdapterForFindImagesByFlybaseGeneID(success);</span>
        var successChain = flyui.chain(flyui.flyted.Service.responseToImages, success); 
		var query = flyui.flyted.Service._buildQueryForFindImagesByFlybaseGeneID(flybaseGeneID);	
		<span class="reserved">this</span>.query(query, successChain, failure);
	}catch (error) {
        throw new flyui.UnexpectedException(_context, error);
    }
	
};


flyui.flyted.Service.responseToImages = <span class="reserved">function</span>( response ) {
    var _context = <span class="literal">"flyui.flyted.Service.responseToImages"</span>;
    try {
        flyui.debug(<span class="literal">"response status: "</span>+response.status, _context);
        flyui.debug(<span class="literal">"try parsing response text as json"</span>, _context);
        flyui.debug(<span class="literal">"response text: "</span>+response.responseText, _context);
        var resultSet = YAHOO.lang.JSON.parse(response.responseText);
        flyui.debug(<span class="literal">"convert result set to an array of genes"</span>, _context);
        var images = flyui.flyted.Image.newInstancesFromSPARQLResults(resultSet);
        <span class="reserved">return</span> images;
    } catch (e) {
        flyui.debug(<span class="literal">"caught "</span>+e.name+<span class="literal">", "</span>+e.message, _context);
        throw new flyui.UnexpectedException(_context, e);
    }
}

<span class="comment">/**
 * Build a SPARQL query to retrieve images by flyted probe name.
 * <span class="attrib">@param</span> {String} anyName the probe name to search by
 * <span class="attrib">@return</span> a SPARQL query
 * <span class="attrib">@type</span> String
 * <span class="attrib">@private</span>
 * <span class="attrib">@static</span>
 */</span>
flyui.flyted.Service._buildQueryForFindImagesByFlytedProbeName = <span class="reserved">function</span>( probeName ) {

	try {
		var prefixes = 	<span class="literal">"PREFIX flyted: &lt;http://purl.org/net/flyted/schema/&gt; "</span> +
						<span class="literal">"PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; "</span> +
						<span class="literal">"PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; "</span>;
						
		var body = 		<span class="literal">"SELECT DISTINCT *  WHERE { "</span> +
							<span class="literal">"?fullImageURL "</span> +
								<span class="literal">"flyted:probe ?probe ; "</span> +
								<span class="comment">//"flyted:associatesToGene ?gene ; " +</span>
								<span class="literal">"flyted:thumbnail ?thumbnailURL; "</span> +
								<span class="literal">"rdfs:seeAlso ?flytedURL; "</span> +
								<span class="literal">"rdfs:label ?caption ."</span> +
							<span class="literal">"?probe rdfs:label '"</span> + probeName + <span class="literal">"' ."</span> +
						<span class="literal">"}"</span>;
							
		var query = prefixes + body;
	
		<span class="reserved">return</span> query;
	}catch (error) {
        throw new flyui.UnexpectedException(<span class="literal">"flyui.flyted.Service._buildQueryForFindImagesByFlytedProbeName"</span>, error);
    }
};

flyui.flyted.Service._buildQueryForFindImagesByFlybaseGeneID = <span class="reserved">function</span>( flybaseGeneID ) {
	try {
		var prefixes = 	<span class="literal">"PREFIX flyted: &lt;http://purl.org/net/flyted/schema/&gt; "</span> +
						<span class="literal">"PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; "</span> +
						<span class="literal">"PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; "</span>;
						<span class="literal">"PREFIX so: &lt;http://purl.org/obo/owl/SO#&gt; "</span>;
						
		var body = 		<span class="literal">"SELECT DISTINCT ?fullImageURL ?thumbnailURL ?flytedURL ?caption ?probe ?probeLabel WHERE { "</span> +
							<span class="literal">"?probe flyted:hybridisesTranscriptOf &lt;http://openflydata.org/id/flybase/feature/"</span> + flybaseGeneID + <span class="literal">"&gt; ;"</span> +
								<span class="literal">"rdfs:label ?probeLabel ."</span> +
							<span class="literal">"?fullImageURL "</span> +
								<span class="literal">"flyted:probe ?probe ; "</span> +
								<span class="literal">"flyted:thumbnail ?thumbnailURL; "</span> +
								<span class="literal">"rdfs:seeAlso ?flytedURL; "</span> +
								<span class="literal">"rdfs:label ?caption ."</span> +
						<span class="literal">"}"</span>;
							
		var query = prefixes + body;
	
		<span class="reserved">return</span> query;
	}catch (error) {
        throw new flyui.UnexpectedException(<span class="literal">"flyui.flyted.Service._buildQueryForFindImagesByFlybaseGeneID"</span>, error);
    }
};



<span class="comment">/**
 * Map a string to a list of strings via a supplied mapping table,
 * returnimng an empty list if the supplied key is not present. 
 * <span class="attrib">@param</span> {String} key 		a key value to be mapped
 * <span class="attrib">@param</span> {Object} table 	an object with members that are arrays of strings
 * <span class="attrib">@return</span> an array of string values, which may be empty if the given key is not found
 * <span class="attrib">@type</span> [String]
 */</span>
flyui.flyted.Service.mapNameUsingTable = <span class="reserved">function</span> ( key, table ) {
	try {
		var result = table[key];
		<span class="reserved">if</span> (typeof result == <span class="literal">"undefined"</span> || !result ) {
			result = [];
		}
		<span class="reserved">return</span> result;
	}catch (error) {
        throw new flyui.UnexpectedException(<span class="literal">"flyui.flyted.Service.mapNameUsingTable"</span>, error);
    }
};


<span class="comment">/**
 * TDO doc me
 */</span>
flyui.flyted.Image = <span class="reserved">function</span> () {
	
	<span class="comment">/**
	 * <span class="attrib">@type</span> String
	 */</span>
	<span class="reserved">this</span>.fullImageURL = null;
	
	<span class="comment">/**
	 * <span class="attrib">@type</span> String
	 */</span>
	<span class="reserved">this</span>.thumbnailURL = null;
	
	<span class="comment">/**
	 * <span class="attrib">@type</span> String
	 */</span>
	 
	<span class="reserved">this</span>.flytedURL = null;
	
	<span class="comment">/**
	 * <span class="attrib">@type</span> String
	 */</span>
	<span class="reserved">this</span>.caption = null;
	
	<span class="comment">/**
	 * <span class="attrib">@type</span> String
	 */</span>
	<span class="reserved">this</span>.probe = null;
	

};


<span class="comment">/**
 * TODO doc me
 */</span>
flyui.flyted.Image.newInstancesFromSPARQLResults = <span class="reserved">function</span>(resultSet){
	try {
		var bindings = resultSet.results.bindings;
		var imagePool = new flyui.flyted.ImagePool();
		var probePool = new flyui.flyted.ProbePool();
		
		<span class="reserved">for</span> (var i=0; i&lt;bindings.length; i++) {
			var binding = bindings[i];
			
			var imageURI = binding.fullImageURL.value;
			<span class="comment">//TODO</span>
			var image = imagePool.get(imageURI);
			image.fullImageURL = binding.fullImageURL.value;
			image.thumbnailURL = binding.thumbnailURL.value;
			image.flytedURL = binding.flytedURL.value;
			image.caption = binding.caption.value;
			
			<span class="reserved">if</span> (binding.probe){
				var probeURI = binding.probe.value;
				var probe = probePool.get(probeURI);
				
				<span class="reserved">if</span> (!probe.probeLabels){
					probe.probeLabels = new Array();
				}
	
				<span class="reserved">if</span> (binding.probeLabel) {
					var probeLabel = binding.probeLabel.value;
					flyui.util.appendIfNotMember(probe.probeLabels, probeLabel);
				}
				image.probe = probe;
			}		
		}
		
		<span class="reserved">return</span> imagePool.toArray();
	}catch (error) {
        throw new flyui.UnexpectedException(<span class="literal">"flyui.flyted.Image.newInstancesFromSPARQLResults"</span>, error);
    }
};


flyui.flyted.ImagePool = <span class="reserved">function</span>() {
	<span class="comment">/**
	 * <span class="attrib">@private</span>
	 */</span>
	<span class="reserved">this</span>._pool = new Object();
};

flyui.flyted.ImagePool.<span class="reserved">prototype</span>.toArray = <span class="reserved">function</span>() {
	try {
		var array = new Array();
		<span class="reserved">for</span> (var key in <span class="reserved">this</span>._pool) {
			array[array.length] = <span class="reserved">this</span>._pool[key];
		}
		<span class="reserved">return</span> array;
	} catch (error) {
        throw new flyui.UnexpectedException(<span class="literal">"flyui.flyted.ImagePool.prototype.toArray"</span>, error);
    }
};

flyui.flyted.ImagePool.<span class="reserved">prototype</span>.get = <span class="reserved">function</span>( imagepath ) {
	
	try {
		var image = <span class="reserved">this</span>._pool[imagepath];
	
		<span class="reserved">if</span> ( typeof image == <span class="literal">"undefined"</span> || !image ) {
			image = new flyui.flyted.Image();		
			<span class="reserved">this</span>._pool[imagepath] = image;	
		}
		
		<span class="reserved">return</span> image;
	} catch (error) {
        throw new flyui.UnexpectedException(<span class="literal">"flyui.flyted.ImagePool.prototype.get"</span>, error);
    }
};

flyui.flyted.ProbePool = <span class="reserved">function</span>() {
	<span class="comment">/**
	 * <span class="attrib">@private</span>
	 */</span>
	<span class="reserved">this</span>._pool = new Object();
};

flyui.flyted.ProbePool.<span class="reserved">prototype</span>.get = <span class="reserved">function</span>( probeURI ) {
	
	try {
		var probe = <span class="reserved">this</span>._pool[probeURI];
		
		<span class="reserved">if</span> (!probe ) {
			probe = new Object();
			probe.probeURI = probeURI;
			<span class="reserved">this</span>._pool[probeURI] = probe;	
		}
		
		<span class="reserved">return</span> probe;
	} catch (error) {
        throw new flyui.UnexpectedException(<span class="literal">"flyui.flyted.ProbePool.prototype.get"</span>, error);
    }
};

flyui.flyted.ProbePool.<span class="reserved">prototype</span>.toArray = <span class="reserved">function</span>() {
	try {
		var array = new Array();
		<span class="reserved">for</span> (var key in <span class="reserved">this</span>._pool) {
			array[array.length] = <span class="reserved">this</span>._pool[key];
		}
		<span class="reserved">return</span> array;
	} catch (error) {
        throw new flyui.UnexpectedException(<span class="literal">"flyui.flyted.ProbePool.prototype.toArray"</span>, error);
    }
};</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>FlyUI</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Tue Dec  9 11:08:18 2008</div>
</body>
</html>
